package com.hongye.app.model;

import java.util.List;

import com.hongye.util.Utils;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

public class TakeOutModel extends Model<TakeOutModel>{

	private static final long serialVersionUID = -4741805154001250732L;
	public static final TakeOutModel dao = new TakeOutModel();
	
	/**
	 * 通过ID获取TakeOutModel
	 * @author lifuqiang
	 * 2017-4-14
	 * @param id
	 * @return
	 */
	public static TakeOutModel getTakeOut_By_id(String id){
		return dao.findById(id);
	}
	
	/**
	 * 获取提现申请列表
	 * @author lifuqiang
	 * 2017-4-14
	 * @return
	 */
	public static List<TakeOutModel> getTakeOutList(){
		String sql = "select * from takeout where type = 1 order by c_time desc";
		List<TakeOutModel> list = dao.find(sql);
		for(TakeOutModel takeout : list){
			BuyerStatisticsModel shop = BuyerStatisticsModel.getStatisticsByID(takeout.get("buyer_id").toString());
			takeout.put("shop_name", shop.get("shop_name"));
		}
		return list;
	}
	
	/**
	 * 通过提现申请ID修改为完成提现状态
	 * @author lifuqiang
	 * 2017-4-14
	 * @param id
	 * @return
	 */
	public static boolean finishTakeOut(String id){
		TakeOutModel takeout = dao.findById(id);
		return takeout.set("status", 1).update();
	}
	
	/**
	 * 通过手机号获取全部提现列表
	 * @author lifuqiang
	 * 2017-4-19
	 * @param phone
	 * @param pageNumber
	 * @return
	 */
	public static Page<TakeOutModel> TakeOutDetailList_By_phone(String phone, int pageNumber){
		String sql = "select id, buyer_phone, money, status, type, c_time";
		String str = " from takeout where buyer_phone = '"+phone+"' order by c_time desc";
		Page<TakeOutModel> list = dao.paginate(pageNumber, Utils.pageSize, sql, str);
		return list;
	}
	
	/**
	 * 通过id 获取提现详情
	 * @author lifuqiang
	 * 2017-4-19
	 * @param id
	 * @return
	 */
	public static TakeOutModel TakeOutDetail_By_id(String id){
		String sql = "select content, buyer_phone, money, banktype, bankcard,leave_money, status, c_time from takeout where id = '"+id+"'";
		return dao.findFirst(sql);
	}
	
}
